<%--
  Created by IntelliJ IDEA.
  User: LSD
  Date: 2018/10/2
  Time: 22:28
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page trimDirectiveWhitespaces="true" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="common" uri="http://itcast.cn/commons/" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>学生信息管理</title>

    <!-- Bootstrap Core CSS -->
    <link href="<%=basePath%>css/bootstrap.min.css" rel="stylesheet">

    <!-- MetisMenu CSS -->
    <link href="<%=basePath%>css/metisMenu.min.css" rel="stylesheet">

    <!-- DataTables CSS -->
    <%--<link href="<%=basePath%>css/dataTables.bootstrap.css" rel="stylesheet">--%>

    <!-- Custom CSS -->
    <link href="<%=basePath%>css/sb-admin-2.css" rel="stylesheet">

    <!-- Custom Fonts -->
    <link href="<%=basePath%>css/font-awesome.min.css" rel="stylesheet"
          type="text/css">
    <link href="<%=basePath%>css/boot-crm.css" rel="stylesheet"
          type="text/css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

</head>

<div id="wrapper">

<!-- 导航栏 -->
<nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0">

<!--导航栏左侧-->
<div class="navbar-header">
    <button type="button" class="navbar-toggle" data-toggle="collapse"
            data-target=".navbar-collapse">
        <span class="sr-only">Toggle navigation</span> <span
            class="icon-bar"></span> <span class="icon-bar"></span> <span
            class="icon-bar"></span>
    </button>
    <a class="navbar-brand" href="${pageContext.request.contextPath }/jsp/index.jsp">首页</a>
</div>
<!--导航栏左侧下面部分-->
<div class="navbar-default sidebar" role="navigation">
    <div class="sidebar-nav navbar-collapse">
        <ul class="nav" id="side-menu">
            <li class="sidebar-search">
                <div class="input-group custom-search-form">
                    &emsp;&emsp;&emsp;&nbsp;<img src="../img/111.jpg" alt="" height="70px" width="90px"/>
                </div> <!-- /input-group -->
            </li>
            <li>
                <a href="#" class="active">
                    <i class="fa fa-edit fa-fw"></i>
                    教师信息
                </a>
                <table>
                    <tr><td>&emsp;&emsp;&emsp;&emsp;账&nbsp;&nbsp;&nbsp;号：${tea.tea_id}<br></td></tr>
                    <tr><td>&emsp;&emsp;&emsp;&emsp;姓&nbsp;&nbsp;&nbsp;名：${tea.tea_name}<br></td></tr>
                    <tr><td>&emsp;&emsp;&emsp;&emsp;部&nbsp;&nbsp;&nbsp;门：${tea.tea_department}<br></td></tr>
                </table>
            </li>
            <li>
                <a href="#">
                    <i class="fa fa-dashboard fa-fw"></i>
                    学生信息
                </a>
            </li>
        </ul>
    </div>
    <!-- /.sidebar-collapse -->
</div>

    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">学生信息管理</h1>
            </div>
            <!-- /.col-lg-12 -->
        </div>
        <!-- /.row -->
        <div class="panel panel-default">
            <div class="panel-body">
                <form class="form-inline" name="findForm" action="" method="post">
                    <div class="form-group">
                        <label for="stuName">学号</label>
                        <input type="text" class="form-control" id="stuName"  name="stuName">
                    </div>
                    <button type="submit" class="btn btn-primary" onclick="findForm.action='${pageContext.request.contextPath }/teaServlet?method=findStuById&id=${tea.tea_id}';findForm.submit();">查询</button>
                    <button type="submit" class="btn btn-primary" onclick="findForm.action='${pageContext.request.contextPath }/teaServlet?method=findStusById&id=${tea.tea_id}';findForm.submit();">查询所有</button>
                </form>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <div class="panel-heading">学生信息列表</div>
                    <!-- /.panel-heading -->
                    <table class="table table-bordered table-striped"  >
                        <thead>
                        <tr >
                            <th>学号</th>
                            <th>姓名</th>
                            <th>性别</th>
                            <th>学院</th>
                            <th>班级</th>
                            <th>学院信息</th>
                            <th>团委</th>
                            <th>组织部</th>
                            <th>图书馆</th>
                            <th>教务处</th>
                            <th>财务处</th>
                            <th>宿管科</th>
                            <th>国有资产</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>

                            <c:forEach items="${tea.teaLists}" var="item">

                        <%--<c:forEach items="${page.rows}" var="item">--%>
                            <tr valign="middle" align="center">
                                <td>${item.stu_id}</td>
                                <td>${item.stu_name}</td>
                                <td>${item.stu_sex}</td>
                                <td>${item.stu_col}</td>
                                <td>${item.stu_cla}</td>
                                <td>${item.stu_col_info}</td>
                                <td>${item.stu_youth_info}</td>
                                <td>${item.stu_org_info}</td>
                                <td>${item.stu_lib_info}</td>
                                <td>${item.stu_off_info}</td>
                                <td>${item.stu_fina_info}</td>
                                <td>${item.stu_domi_info}</td>
                                <td>${item.stu_manage_info}</td>
                                <td>
                                    <a href="#" class="btn btn-primary btn-xs" data-toggle="modal"
                                       data-target="#stuEditDialog" onclick="editStu(${item.stu_id})">修改</a>
                                </td>
                            </tr>
                        </c:forEach>
                        </tbody>
                    </table>
                    <div class="col-md-12 text-right">
                        <common:page url="${pageContext.request.contextPath }/teaServlet?method=teaLogin"/>
                    </div>
                    <!-- /.panel-body -->
                </div>
                <!-- /.panel -->
            </div>
            <!-- /.col-lg-12 -->
        </div>
    </div>
    <!-- /#page-wrapper -->
</nav>
</div>

<!-- 编辑对话框 -->
<div class="modal fade" id="stuEditDialog" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">修改学生信息</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" id="edit_stu_form" method="post">

                    <input type="hidden" id="edit_stu_id" name="stu_id"/>

                    <div class="form-group">
                        <label for="edit_col_info" style="float:left;padding:7px 15px 0 27px;">学院信息</label>
                        <div class="col-sm-10">
                            <select class="form-control" id="edit_col_info"  name="stu_col_info">
                                <c:forEach items="${colInfo}" var="item">
                                    <option value="${item.id}">
                                        ${item.status}
                                    </option>
                               </c:forEach>
                           </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="edit_youth_info" style="float:left;padding:7px 15px 0 27px;">团&emsp;&nbsp;&nbsp;委&nbsp;</label>
                        <div class="col-sm-10">
                            <select class="form-control" id="edit_youth_info"  name="stu_youth_info">
                                <c:forEach items="${youthInfo}" var="item">
                                    <option value="${item.id}">
                                            ${item.status}
                                    </option>
                                </c:forEach>
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="edit_org_info" style="float:left;padding:7px 15px 0 27px;">组 织 部&nbsp;</label>
                        <div class="col-sm-10">
                            <select class="form-control" id="edit_org_info"  name="stu_org_info">
                                <c:forEach items="${orgInfo}" var="item">
                                <option value="${item.id}">
                                        ${item.status}
                                </option>
                            </c:forEach>
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="edit_lib_info" style="float:left;padding:7px 15px 0 27px;">图 书 馆&nbsp;</label>
                        <div class="col-sm-10">
                            <select class="form-control" id="edit_lib_info" name="stu_lib_info">
                                <c:forEach items="${libInfo}" var="item">
                                    <option value="${item.id}">
                                            ${item.status}
                                    </option>
                                </c:forEach>
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="edit_off_info" style="float:left;padding:7px 15px 0 27px;">教 务 处&nbsp;</label>
                        <div class="col-sm-10">
                            <select class="form-control" id="edit_off_info"  name="stu_off_info">
                                <c:forEach items="${offInfo}" var="item">
                                    <option value="${item.id}">
                                            ${item.status}
                                    </option>
                                </c:forEach>
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="edit_fina_info" style="float:left;padding:7px 15px 0 27px;">财 务 处&nbsp;</label>
                        <div class="col-sm-10">
                            <select class="form-control" id="edit_fina_info"  name="stu_fina_info">
                                <c:forEach items="${finaInfo}" var="item">
                                    <option value="${item.id}">
                                            ${item.status}
                                    </option>
                                </c:forEach>
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="edit_domi_info" style="float:left;padding:7px 15px 0 27px;" >宿 管 科&nbsp;</label>
                        <div class="col-sm-10">
                            <select class="form-control" id="edit_domi_info"  name="stu_domi_info">
                                <c:forEach items="${domiInfo}" var="item">
                                    <option value="${item.id}">
                                            ${item.status}
                                    </option>
                                </c:forEach>
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="edit_manage_info" style="float:left;padding:7px 15px 0 27px;">国有资产</label>
                        <div class="col-sm-10">
                            <select class="form-control" id="edit_manage_info"  name="stu_manage_info">
                                <c:forEach items="${manageInfo}" var="item">
                                    <option value="${item.id}">
                                            ${item.status}
                                    </option>
                                </c:forEach>
                            </select>
                        </div>
                    </div>

                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="updateStu()">保存修改</button>
            </div>
        </div>
    </div>
</div>
<!-- /#wrapper -->

<!-- jQuery -->
<script src="<%=basePath%>js/jquery.min.js"></script>

<!-- Bootstrap Core JavaScript -->
<script src="<%=basePath%>js/bootstrap.min.js"></script>

<!-- Metis Menu Plugin JavaScript -->
<script src="<%=basePath%>js/metisMenu.min.js"></script>

<!-- DataTables JavaScript -->
<script src="<%=basePath%>js/jquery.dataTables.min.js"></script>
<script src="<%=basePath%>js/dataTables.bootstrap.min.js"></script>

<!-- Custom Theme JavaScript -->
<script src="<%=basePath%>js/sb-admin-2.js"></script>

<script type="text/javascript">
    function editStu(id) {
        $.ajax({
            type: "post",
            url: "${pageContext.request.contextPath}/stuServlet?method=findStuById",
            data: {"id": id},
            dataType: "json",
            success: function (data) {
                $("#edit_stu_id").val(data.stu_id);
                //这里改变的是option标签的value值
                $("#edit_col_info").val(data.stu_col_info);
                $("#edit_youth_info").val(data.stu_youth_info);
                $("#edit_org_info").val(data.stu_org_info);
                $("#edit_lib_info").val(data.stu_lib_info);
                $("#edit_off_info").val(data.stu_off_info);
                $("#edit_fina_info").val(data.stu_fina_info);
                $("#edit_domi_info").val(data.stu_domi_info);
                $("#edit_manage_info").val(data.stu_manage_info);
            }
        });
    }
    function updateStu() {
        //alert($("#edit_stu_form").serialize());
        $.post("${pageContext.request.contextPath}/stuServlet?method=updateStu", $("#edit_stu_form").serialize(), function (data) {
            if (data == "1") {
                alert("学生信息修改成功！");
            } else {
                alert("学生信息修改失败！");
            }
            window.location.reload();
        });
    }
</script>
</body>
</html>